import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Bg')
export class Bg extends Component {

    @property(Node)
    bg01: Node = null;
    @property(Node)
    bg02: Node = null;
    @property
    speed: number = 100;

    BgHeight: number = 852;


    start() {

    }

    update(deltaTime: number) {
        let position1 = this.bg01.position;
        this.bg01.setPosition(position1.x, position1.y - this.speed * deltaTime);

        let position2 = this.bg02.position;
        this.bg02.setPosition(position2.x, position2.y - this.speed * deltaTime);

        let p1 = this.bg01.position;
        let p2 = this.bg02.position;

        if (this.bg01.position.y < -1 * this.BgHeight) {
            this.bg01.setPosition(p2.x, p2.y + this.BgHeight);
        }
        if (this.bg02.position.y < -1 * this.BgHeight) {
            this.bg02.setPosition(p1.x, p1.y + this.BgHeight);
        }

    }
}


